﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Employees_EmpInsuranceDetail : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeComponent();
            if (Request["action"] != null)
            {
                if (Request["action"].ToString() != "add")
                {
                    if (Request["action"].ToString() != "onlyadd")
                    {
                        WMaster.SetWhere("InsuranceDataId=" + Request["Iid"].ToString());
                    }

                    hidEid.Value = Request["eid"].ToString();
                    hidEname.Value = Server.UrlDecode(Request["ename"]);
                }
                else
                {
                    WMaster.SetWhere("1=0");
                }
                
                
            }
            Master.DataSource = WMaster;


            MasterPage_MasterPage master = (MasterPage_MasterPage)this.Page.Master;

            master.HelpHref = "";
            master.PageName = "保险明细";
            master.PicUrl = "~/image/PageIcon/hetong.jpg";
            master.IntiBar();
          
        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Employees_EmpInsuranceDetail));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SEmployees.EmpInsurance";
        this.WMaster.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }
    protected void EmpInsurance_DataBound(object sender, EventArgs e)
    {
        //SelUser 
        //Control_SelUser su = EmpInsurance.FindControl("SelUser") as Control_SelUser;

        //su.ReadOnly(Request["eid"].ToString(), Request["ename"].ToString());

        if (Request["action"] != null)
        {
            if (Request["action"].ToString() == "self" || Request["action"].ToString() == "view")
            {
                wn.Visible = false;
            }
            //else if (Request["action"].ToString() == "edit")
            //{
            //    wn.NavControls.Remove(wn.NavControls["Add"]);
            //}
            else if (Request["action"].ToString() == "onlyadd")
            {
                DivBack.Visible = false;
            }
        }

        if (hidEid.Value != "")
        {
            Control_SelUser su = EmpInsurance.FindControl("SelUser") as Control_SelUser;

            su.ReadOnly(hidEid.Value, hidEname.Value);

        }
        else
        {
            Control_SelUser su = EmpInsurance.FindControl("SelUser") as Control_SelUser;
            su.SelUserInti("0", "");

            wn.NavControls.Remove(wn.NavControls["Update"]);
        }
        //if (Master.CurrentRow["Contractend"].ToString() == "")
        //{
        //    wn.NavControls.Remove(wn.NavControls["Add"]);
        //}
        //else if (Request["action"] != null)
        //{
        //    wn.Visible = false;
        //}
        //else
        //{
        //    wn.NavControls.Remove(wn.NavControls["Update"]);
        //}

        //MasterHr.CurrentRow["DepartmentId"].ToString()
        

    }


    protected void wnHr_Command(object sender, CommandEventArgs e)
    {


        if (e.CommandName == "cmdFirst" || e.CommandName == "cmdPrevious"
            || e.CommandName == "cmdNext" || e.CommandName == "cmdLast")
        {
            Master.ExecuteSelect(EmpInsurance);
            DataBind();
        }
        else if (e.CommandName == "cmdAdd")
        {
            //Master.ExecuteAdd(Contract);
            DataBind();
        }
        else if (e.CommandName == "cmdDelete")
        {
            Master.ExecuteSelect(EmpInsurance);
            DataBind();
        }
        else if (e.CommandName == "cmdApply" && EmpInsurance.AllValidateSucess)
        {
            Master.ExecuteSelect(EmpInsurance);
            DataBind();
            if (Request["action"] != null)
            {
                if (Request["action"].ToString() == "onlyadd")
                {
                    ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('添加成功');parent.location.reload()", true);
                }
            }
        }
    }

    protected void Back_Click(object sender, EventArgs e)
    {
        Response.Redirect(Server.HtmlDecode(Request["redurl"].ToString()));
    }

   
    protected void Master_Adding(object sender, Srvtools.WebDataSourceAddingEventArgs e)
    {
        try
        {
            Control_SelUser su = EmpInsurance.FindControl("SelUser") as Control_SelUser;
            if (su.EmployeeId == "")
            {
                return;
            }
            else
            {
                e.AddingValues["EmployeeID"] = su.EmployeeId;

                hidEid.Value = su.EmployeeId;
                hidEname.Value = su.EmpName;
            }
        }
        catch
        {
            return;
        }


    }
}
